package com.itheima.api.hashmap.demo02;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashDemo02 {

    public static void main(String[] args) {

        Student s1 = new Student("蓝湛", 15);
        Student s2 = new Student("魏婴", 14);
        Student s3 = new Student("蓝涣", 16);
        Student s4 = new Student("蓝湛", 15);

        HashMap<String, Student> hashMap = new HashMap<String, Student>();
        hashMap.put("stu001", s1);
        hashMap.put("stu002", s2);
        hashMap.put("stu003", s3);
        hashMap.put("stu004", s4);

        Set<Map.Entry<String, Student>> entrySet = hashMap.entrySet();
        for (Map.Entry<String, Student> entry : entrySet){
//            String name = entry.getKey().getName();
            System.out.println(entry.getKey() + "," + entry.getValue().getName() + "," + entry.getValue().getAge());
        }
        System.out.println("------------------------");

        hashMap.forEach((String key, Student stu) -> {
            String name = stu.getName();
            int age = stu.getAge();
            System.out.println(key + "=" + name + "=" + age);
        });

        //第四道练习题：key是student,value也是student
    }
}
